import { view, updateBasis, updatePersonal, updateModule, updateAbout } from './api'

export default {
  namespaced: true,
  state: () => ({
    basis: {},
    module: {},
    personal: {},
    about: {}
  }),
  getters: {
    basis (state) {
      return state.basis
    },
    module (state) {
      return state.module
    },
    personal (state) {
      return state.personal
    },
    about (state) {
      return state.about
    }
  },
  actions: {
    async view ({ commit }, type) {
      const { data } = await view(type)
      commit('SET_' + type.toUpperCase(), data)
    },
    async updateBasis ({ commit }, params) {
      const { data } = await updateBasis(params)
      commit('SET_BASIS', data)
    },
    async updateModule ({ commit }, params) {
      const { data } = await updateModule(params)
      commit('SET_MODULE', data)
    },
    async updatePersonal ({ commit }, params) {
      const { data } = await updatePersonal(params)
      commit('SET_PERSONAL', data)
    },
    async updateAbout ({ commit }, params) {
      const { data } = await updateAbout(params)
      commit('SET_ABOUT', data)
    }
  },
  mutations: {
    SET_BASIS (state, payload) {
      state.basis = payload.data
    },
    SET_MODULE (state, payload) {
      state.module = payload.data
    },
    SET_PERSONAL (state, payload) {
      state.personal = payload.data
    },
    SET_ABOUT (state, payload) {
      state.about = payload.data
    }
  }
}
